﻿using mars_client.csharp.cache;
using mars_client.csharp.enums;
using mars_client.csharp.model;
using mars_client.csharp.model.vo;
using mars_client.csharp.radar;
using mars_client.csharp.util;
using mars_client.csharp.vo;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace mars_client.gui.page
{
    /// <summary>
    /// SingleChat.xaml 的交互逻辑
    /// </summary>
    public partial class GroupChatPage : Page
    {
        public GroupChatPage()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 发消息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            sendMessage();
        }

        private void sendMessage()
        {
            MessageCO messageCO = new MessageCO();
            messageCO.type = (int)RequestEnum.request.GroupChatContent;

            GroupChatVO groupChatVO = new GroupChatVO();
            groupChatVO.senderVO = UserCache.Instance.userVO;
            groupChatVO.messageVO = new MessageVO();
            groupChatVO.messageVO.message = sendText.Text.ToString();
            groupChatVO.groupVO = new GroupVO();
            groupChatVO.groupVO.id = long.Parse(this.Uid);
            groupChatVO.groupVO.groupName = remoteName.Text.ToString();
            groupChatVO.groupVO.groupIntro = intro.Text.ToString();

            messageCO.content = groupChatVO;

            Radar.Instance.sendData(messageCO);

            // 自己的消息直接赋值
            SingleChatVO singleChatVO1 = new SingleChatVO();
            singleChatVO1.senderVO = new UserVO();
            singleChatVO1.receiverVO = new UserVO();
            singleChatVO1.messageVO = new MessageVO();

            singleChatVO1.sendTime = DateTime.Now.ToLongTimeString().ToString();
            singleChatVO1.senderVO = UserCache.Instance.userVO;
            singleChatVO1.messageVO.message = sendText.Text;
            this.contentWrapper.Children.Add(RenderUtil.generateChatTemp(singleChatVO1, "right"));

            sendText.Text = "";
        }

        private void Image_MouseUp(object sender, MouseButtonEventArgs e)
        {
            MessageCO messageCO = new MessageCO();
            messageCO.type = (int)RequestEnum.request.GetGroupUsers;
            GroupVO groupVO = new GroupVO();
            groupVO.id = long.Parse(this.Uid);
            messageCO.content = groupVO;

            Radar.Instance.sendData(messageCO);
        }

        private void sendText_KeyUp(object sender, KeyEventArgs e)
        {
            if(e.Key == Key.Enter)
            {
                sendMessage();
            }
        }
    }
}
